﻿using Com.JunCaiSoft.AutoMapper;
using Com.JunCaiSoft.Freeze.Dto;
using Com.JunCaiSoft.Freeze.Entity;
using Com.JunCaiSoft.Freeze.Model;
using Microsoft.AspNetCore.Builder;
using System;

namespace Com.JunCaiSoft.Freeze
{
    public static class FreezeAutoMapperConfigure
    {
        public static void CreateFreezeMapper(IApplicationBuilder app)
        {
            var creator = app.UseAutoMapper();

            #region 冻结资金实体映射
            creator.CreateMap<FreezeMoneyItemDto, FreezeMoneyItem>()
                .ForMember(dest => dest.FreezeTime, opt => opt.MapFrom(src => src.FreezeTime.ToString("yyyy-MM-dd")))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")));
            creator.CreateMap<FreezeMoneyView, FreezeMoney>()
                .ForMember(dest => dest.PreservationInfo, opt => opt.MapFrom(src => src.PreservationInfo.Id))
                .ForMember(dest => dest.FundsType, opt => opt.MapFrom(src => Int32.Parse(src.FundsType)))
                .ForMember(dest => dest.CreditContractInfo, opt => opt.MapFrom(src => src.CreditContractInfo.Id))
                .ForMember(dest => dest.FreezeOperatorId, opt => opt.MapFrom(src => src.FreezeOperator.Id));
            //creator.CreateMap<FreezeMoney, FreezeMoneyView>()
            //    .ForMember(dest => dest.BankName, opt => opt.Ignore())
            //    .ForMember(dest => dest.Account, opt => opt.Ignore())
            //    .ForMember(dest => dest.ProjectCode, opt => opt.Ignore())
            //    .ForMember(dest => dest.ProjectName, opt => opt.Ignore());
            #endregion

            #region 借条实体映射
            creator.CreateMap<CreditContractItem, CreditContractItemDto>();
            creator.CreateMap<CreditContractItemDto, CreditContractItem>()
                .ForMember(dest => dest.FreezeMoneyList,opt => opt.Ignore());
            creator.CreateMap<CreditContractView, CreditContract>();
            creator.CreateMap<CreditContract, CreditContractView>()
                .ForMember(dest => dest.FreezeMoneyList,opt => opt.Ignore());
            #endregion

            #region 解冻资金实体映射
            //creator.CreateMap<UnFreezeMoneyItem, UnFreezeMoneyItemDto>();
            //creator.CreateMap<UnFreezeMoneyItemDto, UnFreezeMoneyItem>();
            //creator.CreateMap<UnFreezeMoneyView, UnFreezeMoney>();
            //creator.CreateMap<UnFreezeMoney, UnFreezeMoneyView>();
            #endregion
        }
    }
}
